package com.leetcode.LC;

public class LC762 {
    public int countPrimeSetBits(int L, int R) {

        int count=0;
        for (int i = L; i <= R; i++) {
            if (isPrimeNumber(oneNum(i))){
                count++;
            }
        }
        return count;
    }

    //计算1的个数
    public int oneNum(int num){
        int count=0;
        String s = Integer.toBinaryString(num);
        for (int i = 0; i < s.length(); i++) {
            if(s.charAt(i)=='1'){
                count++;
            }
        }
        return count;
    }

    //判断是不是质数
    public boolean isPrimeNumber(int num) {
        if (num == 2 || num == 3 || num == 5 || num == 7) {
            return true;
        } else if (num == 1) {
            return false;
        }
        for (int i = 2; i <= Math.sqrt(num); i++) {
            if (num % i == 0) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(new LC762().countPrimeSetBits(10, 15));
    }
}
